package com.yunqiao.admin.modules.api.controller;

import com.yunqiao.common.utils.PageUtils;
import com.yunqiao.common.utils.R;
import com.yunqiao.service.api.ArticleService;
import com.yunqiao.service.api.entity.ArticleEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 文章表
 *
 * @author Crocutax
 * @email wangxw725@163.com
 * @date 2019-03-02 15:04:03
 */
@RestController
@RequestMapping("api/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("api:article:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = articleService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("api:article:info")
    public R info(@PathVariable("id") Long id){
        ArticleEntity article = articleService.getById(id);
        return R.ok().put("article", article);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("api:article:save")
    public R save(@RequestBody ArticleEntity article){
        articleService.save(article);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("api:article:update")
    public R update(@RequestBody ArticleEntity article){
        articleService.updateById(article);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("api:article:delete")
    public R delete(@RequestBody Integer[] ids){
        articleService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
